<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>社团信息</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name=”apple-mobile-web-app-status-bar-style” content=”default” />
    <meta name=”apple-mobile-web-app-status-bar-style” content=”black” />
    <meta name=”apple-mobile-web-app-status-bar-style” content=”black-translucent” />
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="format-detection" content="telephone=no"/>

    <link href="${s.base}/mobile/css/weui.min.css" rel="stylesheet" />
    <link href="${s.base}/mobile/css/jquery-weui.css" rel="stylesheet" />
    <link href="${s.base}/mobile/css/swiper.min.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/reset.css" rel="stylesheet" />
    <link href="${s.base}/mobile/css/weChat.css" rel="stylesheet">
</head>
<body>
<div class="weui-pull-to-refresh__layer">
    <div class="pull-to-refresh__arrow"></div> <!-- 上下拉动的时候显示的箭头 -->
    <div class="pull-to-refresh__preloader"></div> <!-- 正在刷新的菊花 -->
    <div class="down">下拉刷新</div><!-- 下拉过程显示的文案 -->
    <div class="up">释放刷新</div><!-- 下拉超过50px显示的文案 -->
    <div class="refresh">正在刷新...</div><!-- 正在刷新时显示的文案 -->
</div>
<!--tab切换按钮-->
<div class="mian-ctn">
<div class="flexmenu-line"></div>
<div class="top-twotab-btn">
    <div class="flexmenutab checked">社团信息</div>
    <div class="flexmenutab">社团人员</div>
</div>
<!--tab切换按钮结束-->
<div class="society-details-ctn clearfix" id="tab1">
</div>
<div class="society-peo-ctn clearfix" id="tab2" style="display:none">
    <ul class="stry" id ='tab2-signlist'>
    </ul>
</div>
</div>

<div class="weui-loadmore">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>

<div class="nodate-ctn" id='nodate-ctn' style="display: none">
    <p>
        <img src="${s.base}/mobile/images/nodates.png"><br>
        <span>暂无数据</span>
    </p>
</div>

</body>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/fontSize.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-weui.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/fastclick.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/common.js"></script>
<script type="text/javascript">
    var scoietyPage = 1;
    var myScoietyPage = 1;
    var limit = 10;
    var loading = false;
    var checkScoiety = true;
    var scoietyHasMore = true;
    var myScoietyHasMore = true;
    var applyId = '${applyId}';
    var token = '${token}';
    var type='${type}';
    var associationId='${associationId}';
    var associationNewId='${associationNewId}';
    $('.weui-loadmore').hide();
    $(".nodate-ctn").css("height", document.body.scrollHeight - 50);
    $(function () {
        FastClick.attach(document.body);
        leftJson('1');
        //rightJson('1');
        // initMySocietyData('1');
        initListener();
    });

    //生成左边社团详情数据
    function leftJson(flag) {
        if (flag === '1') {
            $(document.body).infinite(100);
            scoietyHasMore = true;
        }
        $.fn.doPost('/phone/association/getAssociationDetail', {applyId:applyId,id:associationId,token:token,associationNewId:associationNewId}, function (result) {
           if (result.code === 0) {
//             $.toast(result.msg, "text");
               scoietyHasMore = false;
               $(document.body).destroyInfinite();
               $('#tab1').html('');
               $(document.body).pullToRefreshDone();
               var e=result.data;
               var str= '<div class="st-cover"><img src="/sysFile/showFileByPath?path=' + e.path+'"></div>'+
                   '<div class="st-txt">'+
                   '<h3>社团简介</h3>'+e.introduction+
                   '</div>';
               if(type==1){
                   if(e.signId==''||e.signId==null){
                   str += '<div class="menu-long-bot-xf" onclick="associationAdd(\''+e.id+'\',\''+associationNewId+'\')">立刻报名</div>';}
                   else{
                       str += '<div class="menu-long-bot-xf" onclick="associationQuit(\''+e.id+'\',\''+associationNewId+'\')" >退团</div>';}
                   }
               $('#tab1').html(str);
               $(".nodate-ctn").hide();
            } else {
              $.toast(result.msg, "text");
            }
        });
    }
    //生成右侧社团已报人员名单
    function rightJson(flag){
        if (flag === '1') {
            $(document.body).infinite(100);
            scoietyHasMore = true;
        }

        $.fn.doPost('/phone/associationSign/wxassociationsign/hasAssSign', {applyId:applyId,associationId:associationId,associationNewId:associationNewId,token:token, page: myScoietyPage, limit: limit}, function (result) {
            if (result.code === 0) {
                if (!result.hasNextPage) {
                    scoietyHasMore = false;
                    $(document.body).destroyInfinite();
                }
                if (flag === '1') {
                    $('#tab2-signlist').html('');
                    $(document.body).pullToRefreshDone();
                } else if (flag === '2') {
                    loading = false;
                    $(".weui-loadmore").hide();
                }
                postSocietyData(result.data);
            } else {
                $.toast('获取数据失败', "text");
            }
        });

    }
    function postSocietyData(data){
        var str = '';
        if (data != null && data.length > 0) {
            for (var i = 0; i < data.length; i++) {
                var e = data[i];
                var signTimeStr= new Date(e.signTime).Format("yyyy-MM-dd");
                str +='<li>'+
                    '<div class="st-peo"><img src="../../images/Defaulthead@2x.png"></div>'+
                    '<div class="st-peo-name">'+e.userName+'</div>'+
                    '<div class="st-peo-xh">学号:'+e.userNumber+'</div>'+
                    '<div class="join-st-time"><span>'+signTimeStr+'</span>加入</div>'+
                    '</li>';

            }
            $('#nodate-ctn').hide();
        }
        if (isBlank(str)) {
            $('#nodate-ctn').show();
            $('#tab2-signlist').html(str);
        } else {
            $('#tab2-signlist').html(str);
            // $('.question-list ul').append(str);
        }
    }

    function initListener() {
        //初始化下拉刷新
        $(document.body).pullToRefresh();
        $(document.body).on("pull-to-refresh", function () {
            if(checkScoiety){
                scoietyPage = 1;
                leftJson('1');
            }else{
                myScoietyPage = 1;
                rightJson('1');
            }

        });

        //初始化滚动加载
        $(document.body).infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            $('.weui-loadmore').show();
            setTimeout(function () {
                if(checkScoiety){
                    scoietyPage++;
                    leftJson('1');
                }else{
                    myScoietyPage++;
                    rightJson('2');
                }
            }, 1000);
        });

        $(".flexmenutab").bind("click",function(){
            $(".flexmenutab").removeClass("checked");
            $(this).addClass("checked");
            var tabindex=$(this).index();
            if(tabindex==0){
                $(".flexmenu-line").removeClass("left512").addClass("left138");
                $("#tab2").hide();
                $("#tab1").show();
                $('#nodate-ctn').hide();
                leftJson('1');
                if(scoietyHasMore){
                    $(document.body).infinite(100);
                }
            }
            else{
                $(".flexmenu-line").removeClass("left138").addClass("left512");
                $("#tab1").hide();
                $("#tab2").show();
                rightJson('1');
                if(myScoietyHasMore){
                    $(document.body).infinite(100);
                }
            }
        })

    }
    //报名
    function associationAdd(associationId,associationNewId){
        $.fn.doPost('/phone/associationSign/wxassociationsign/addOrUpdate', {applyId:applyId,associationId:associationId,associationNewId:associationNewId,token:token}, function (result) {
            if (result.code === 0) {
                $.toast(result.msg, "text");
                leftJson('1');
            } else {
                $.toast(result.msg, "text");
            }
        });
    }
    //退团
    function associationQuit(associationId,associationNewId) {
        //退团弹窗
        $.confirm("是否确认退团","温馨提示",function () {
            $.fn.doPost('/phone/associationSign/wxassociationsign/quitAssociation', {applyId:applyId,associationId:associationId,associationNewId:associationNewId,token:token}, function (result) {
                if (result.code === 0) {
                    $.toast(result.msg, "text");
                    leftJson('1');
                } else {
                    $.toast(result.msg, "text");
                }
            });
        },function () {
        });
    }



</script>
</html>

